define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'auth/timetable/index' + location.search,
                    add_url: 'auth/timetable/add',
                    edit_url: 'auth/timetable/edit',
                    del_url: 'auth/timetable/del',
                    multi_url: 'auth/timetable/multi',
                    preview_url: 'auth/timetable/preview',
                    import_url: 'auth/timetable/import',
                    table: 'admin_timetable',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: false,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'admin_id', title: __('Admin_id')},
                        // {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'),
                            buttons: [
                                {
                                    name: 'preview',
                                    text: '预览课表数据',
                                    icon: '',
                                    extend: 'data-area=\'["90%", "90%"]\'',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'auth/timetable/preview',
                                }],
                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
